<?php
namespace app\api\controller;
use think\facade\Db;

class CompanyCheck extends common
{
    private $dbname = 'company';
    public function index()
    {
        return 'company';
    }

    /**
     * 列表分页获取
     * @return string
     */
    public function getlist()
    {
        $data = input('get.');

        $where = [];
        if(!empty($data['name'])){
            $where[] = ['company.name
                |company.username
                |company.license_code
                |company.credit_code
                |company.corporation
                |company.phone
                |company.user_phone
                |company.credit_code
                ','like','%'.$data['name'].'%'];
        }
        if(!empty($data['passed']) || $data['passed'] == '0'){
            $where[] = ['passed','=',$data['passed']];
        }

        $list = Db::view($this->dbname,'id,logo,address,name,phone,user_phone,username,address,passed,check,status,corporation,credit_code,time')
            ->where($where)
            ->order('status desc,passed desc,id desc')
            ->paginate([
                'list_rows'=> $data['limit'],
                'var_page' => 'page',
            ])->toArray();
        return re_list($list);
    }

    /**
     * 修改
     * @return false|string|void
     */
    public function check()
    {
        $data = input('put.');
        if(!$data['id']){
            re_warning('错误请求');
        }
//        if(!$data['passed_content']){
//            re_warning('审核情况必须填写');
//        }
        $newdata = [
            'passed'=>$data['passed'],
            'passed_content'=>$data['passed_content'],
            'status'=>$data['passed'] ==1?1:0,
            'check'=>1,
            'id'=>$data['id']
        ];
        $model = new \app\api\model\Company();
        return $model->edit($newdata);

    }

}
